﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace pokerServer.ProtHandlers.Concrete
{
	class UserRequestsProtHandler : IProtHandle
	{
		private global::ConnectionControl.ConnectionManag cm;
		private ushort tableid;
		public GameManagment.GameTools.Player myPlayer;

		public UserRequestsProtHandler(global::ConnectionControl.ConnectionManag cm, GameManagment.GameTools.Player p, String s)
		{
			// TODO: Complete member initialization
			this.cm = cm;
			this.myPlayer = p;
			this.tableid = Convert.ToUInt16(s);
		}


		public string work()
		{
			try {
				GameManagment.GameTools.Table t = this.cm.tablem.findTable(tableid);
				return pokerServer.GameManagment.GameTools.MessagesProtocol.PlayerListProtocol(t.TableID, t.playerList);
			}
			catch {
				return "REQUEST-PLAYERLIST-FAIL NO_SUCH_TABLE";
			}
			
		}

		public int resolve(String s)
		{
			int i = -1;
			try
			{
				i = Int32.Parse(s);
			}
			catch (System.Exception ex)
			{
				Console.Write(ex.Message);
			}
			return i;
		}
	}
}
